Skip to content

xds: add internal ResourceNameFunc server option - #9288

Open
ran-su wants to merge 9 commits into
grpc:masterfrom
ran-su:xds-server-resource-name-func
Open

xds: add internal ResourceNameFunc server option#9288
ran-su wants to merge 9 commits into
grpc:masterfrom
ran-su:xds-server-resource-name-func

Conversation

@ran-su

@ran-su ran-su commented Aug 3, 2026

Copy link
Copy Markdown
Member

Adds an internal ResourceNameFunc server option that allows override the LDS listener resource name.

RELEASE NOTES: none

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.11111% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.08%. Comparing base (a620350) to head (e9b5060).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
xds/server.go 82.60% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9288      +/-   ##
==========================================
+ Coverage   83.00%   83.08%   +0.08%     
==========================================
  Files         422      424       +2     
  Lines       35085    35252     +167     
==========================================
+ Hits        29121    29289     +168     
- Misses       4441     4448       +7     
+ Partials     1523     1515       -8     
Files with missing lines Coverage Δ
internal/xds/server/server_options.go 100.00% <100.00%> (ø)
xds/server_options.go 100.00% <100.00%> (ø)
xds/server.go 82.55% <82.60%> (ø)

... and 59 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ran-su
ran-su force-pushed the xds-server-resource-name-func branch from 726a5b4 to 5c0a214 Compare August 3, 2026 21:56
@easwars easwars added Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Feature New features or improvements in behavior labels Aug 4, 2026
@easwars easwars added this to the 1.84 Release milestone Aug 4, 2026
@eshitachandwani
eshitachandwani self-requested a review August 12, 2026 16:06
Comment thread xds/server_options.go Outdated
Comment thread xds/server.go Outdated
@ran-su ran-su changed the title xds: add ResourceNameFunc server option and UnderlyingServer method xds: add internal ResourceNameFunc server option Aug 16, 2026
Comment thread internal/xds/server/server_options.go Outdated
Comment thread xds/server_test.go Outdated
Comment thread xds/server_test.go
Comment thread xds/server_test.go

@eshitachandwani eshitachandwani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo 2 comments. Adding @easwars for a second review.

Comment thread xds/server_options.go Outdated
Comment thread internal/xds/server/server_options.go Outdated
Comment thread xds/server_options.go
@easwars easwars removed their assignment Aug 18, 2026

@easwars easwars left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor nits.

Comment thread internal/xds/server/server_options.go Outdated
Comment thread xds/server_test.go Outdated
Comment on lines +241 to +242
if req.GetTypeUrl() == version.V3ListenerURL &&
cmp.Equal(req.GetResourceNames(), []string{wantResourceName}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please don't break up lines this way. Go does not impose line length restriction for code lines. See: https://google.github.io/styleguide/go/guide#line-length

Comment thread xds/server_test.go Outdated
Comment on lines +266 to +272
srv, err := NewGRPCServer(
internalserver.OverrideListenerResourceName(func(addr net.Addr) string {
addrCh <- addr
return wantResourceName
}),
BootstrapContentsForTesting(bs),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Same here. Please don't break this up like this. Pull the server option out into a local variable so that the call to NewGRPCServer can be comfortably placed on a single line. Thanks.

Comment thread xds/server_test.go Outdated
Comment on lines +309 to +319
srv.Stop()
stopped = true
// Verify that Serve returns after the server is stopped.
select {
case err := <-serveErrCh:
if err != nil {
t.Fatalf("Serve() returned error: %v", err)
}
case <-ctx.Done():
t.Fatal("Timeout waiting for Serve() to return")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not pertinent to what is being tested here, right? This should be covered by other tests that focus on Serve returning once Stop is called. So, I would remove all this logic from here and defer a call to srv.Stop and forget about it.

Comment thread xds/server_test.go Outdated
newGRPCServer = func(...grpc.ServerOption) grpcServer { return fs }
defer func() { newGRPCServer = origNewGRPCServer }()

addrCh := make(chan net.Addr, 1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Rename this as lisAddrCh since this variable is used long after it is defined and therefore it is better to have a more descriptive name.

@easwars easwars left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, modulo one minor nit in the test.

Comment thread xds/server_test.go Outdated
// template is absent, and that its returned name is used for the LDS watch.
func (s) TestServer_OverrideListenerResourceNameOverridesMissingTemplate(t *testing.T) {
const wantResourceName = "xdstp://foo/bar"
ldsResourceNameReceived := grpcsync.NewEvent()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Instead of this being a grpcsync.Event, this could be a chan []string. Then, the OnStreamRequest implementation does not need to validate the resource name. It will simply push the received slice of resource names onto this channel. And the main test goroutine at the end will read the value out of the channel and compare it.

The advantage with the approach that I'm suggesting is that if the resource names does not match with the expected value, then the test error message can include it and that will help with debugging when the test fails.

Also, please be aware that this method will be invoked multiple times during the test:

  • The first time the server requests for the LDS resource
  • The ACK for the above resource
  • When the server is shutting down, there is a race where the xDS client might end up sending an LDS request with an empty set of resource names.

So, the write to the channel needs to be guarded with a test context:

select {
  case ldsResourceNames <- req.GetResourceName():
  case <-ctx.Done()
}

Where ctx is the overall test context which is currently defined as

	ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
	defer cancel()

and this would need to be moved to the top.

@ran-su

ran-su commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

@eshitachandwani I have addressed the comments. Could you please take another look at this PR? If this version looks good to you, could you please help me merge it? Thanks.

@eshitachandwani

Copy link
Copy Markdown
Member

Hey @ran-su could you please rebase your PR on master to get the codecov job passing. It has been fixed.
Once it passes I will merge the PR.

@ran-su
ran-su force-pushed the xds-server-resource-name-func branch from 5a68c82 to 12f67c6 Compare August 21, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: xDS Includes everything xDS related, including LB policies used with xDS. Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants